package com.zhong.gang.app.ui.examine;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.View;
import android.widget.PopupWindow;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityExamineBinding;
import com.zhong.gang.app.ui.examine.payment.PayMentAct;
import com.zhong.gang.app.ui.examine.presenter.ExaminePresenter;
import com.zhong.gang.app.ui.examine.price.PriceAct;
import com.zhong.gang.applib.base.act.ActBaseRefresh;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.modle.ListBean;
import com.zhong.gang.applib.pop.TypeBean;
import com.zhong.gang.applib.pop.TypePop;

import java.util.ArrayList;
import java.util.List;
@Deprecated
public class ExamineListAct extends ActBaseRefresh<ActivityExamineBinding,ExamineAdapter>
        implements ExamineAdapter.OnItemClickListener, TypePop.onTypeItemClickedListener , PopupWindow.OnDismissListener{
    protected TypePop typePop,statusPop;
    private int type = 2,status = 2;
    private ExaminePresenter presenter;
    @Override
    public int LayoutRes() {
        return R.layout.activity_examine;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "财务审核";
    }

    @Override
    public void initView() {
        presenter = new ExaminePresenter();
        bind.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        initrefrsh(bind.pullto,new ExamineAdapter(),bind.recyclerView);
        adapter.setOnItemClickListener(this);
       // bind.setAct(this);
        initPop();
        getData();
    }

    /**
     * 初始话pop和dialog
     */
    private void initPop(){
        List<TypeBean> typeList = new ArrayList<>();
        getTypeList(typeList,"全部",2);
        getTypeList(typeList,"价格变更审核",0);
        getTypeList(typeList,"付款审核",1);
        typePop = new TypePop(this,bind.typeLayout,typeList,this);


        List<TypeBean> statusList = new ArrayList<>();
        getTypeList(statusList,"全部",2);
        getTypeList(statusList,"待审核",0);
        getTypeList(statusList,"已审核",1);
        statusPop = new TypePop(this,bind.statusLayout,statusList,this);

        typePop.setOnDismissListener(this);
        statusPop.setOnDismissListener(this);
    }

    @Override
    public void getData() {
        super.getData();
        presenter.getList(this,page,type,status,new ActCallBack<BaseDataBean<ListBean<ExamineBean>>>(){
            @Override
            public void onResponse(BaseDataBean<ListBean<ExamineBean>> data) throws Exception {
                super.onResponse(data);
                setData(data.getResult().getRecords());
            }
        });
    }

    /**
     * 获取typeList
     * @param data
     * @param title
     * @param type
     */
    protected void getTypeList(List<TypeBean> data, String title, int type){
        if (data == null)
            return;
        data.add(new TypeBean(title,type));
    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        ExamineBean bean = (ExamineBean) adapter.getItem(position);
        switch (bean.getType()){
            case 0:
                PriceAct.openAct(this,bean.getId());
                break;
            case 1:
                PayMentAct.openAct(this,bean.getId());
                break;
        }
    }

    @Override
    public void onTypeItem(View view, TypeBean typeBean) {
        if (typeBean == null)
            return;
        int i = view.getId();
        if (i == R.id.type_layout) {
            type = typeBean.getType();
            bind.typeTv.setText(typeBean.getTitle());
        } else if (i == R.id.status_layout) {
            status = typeBean.getType();
            bind.statusTv.setText(typeBean.getTitle());
        }
        onRefresh();
    }

    @Override
    public void onDismiss() {
        bind.typeImg.setImageResource(com.zhong.gang.applib.R.mipmap.icon_down);
        bind.statusImg.setImageResource(com.zhong.gang.applib.R.mipmap.icon_down);
    }

    /**
     * 点击事件
     * @param view
     */
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.type_layout:
                bind.typeImg.setImageResource(com.zhong.gang.applib.R.mipmap.icon_up);
                typePop.showAsDropDown(bind.typeLayout, type);
                break;
            case R.id.status_layout:
                bind.statusImg.setImageResource(com.zhong.gang.applib.R.mipmap.icon_up);
                statusPop.showAsDropDown(bind.statusLayout, status);
                break;
        }
    }
}
